//
//  ReaderViewModel.m
//  BoYue
//
//  Created by drouce on 15/11/26.
//  Copyright © 2015年 drouce. All rights reserved.
//

#import "ReaderViewModel.h"
#import "ReaderModel.h"
#import "ReaderManager.h"


@implementation ReaderViewModel

-(NSInteger)rowNumber {
    return self.dataArr.count;
}

- (RecommendModel *)modelForRow:(NSInteger)row {
    return self.dataArr[row];
   
}

-(NSURL *)iconForRow:(NSInteger)row {

    return [NSURL URLWithString:[self modelForRow:row].imgsrc];
}

-(NSString *)titleForRow:(NSInteger)row {
    return [self modelForRow:row].title;
}

-(NSString *)docIdForRow:(NSInteger)row {
    return [self modelForRow:row].docid;
}

-(void)getDataFromNetCompleteHandle:(CompletionHandle)completionHandle {
    self.dataTask = [ReaderManager getReadInfoWithStartIndex:_index CompletionHandle:^(id model, NSError *error) {

        if (_index == 20) {
            [self.dataArr removeAllObjects];
            //[self.dataArr addObjectsFromArray:model];
        }
        [self.dataArr addObjectsFromArray:model];
        completionHandle(error);
    }];

}

- (void)refreshDataCompletionHandle:(CompletionHandle)completionHandle{
    _index = 20;
    [self getDataFromNetCompleteHandle:completionHandle];
}
- (void)getMoreDataCompletionHandle:(CompletionHandle)completionHandle{
    _index += 10;
    [self getDataFromNetCompleteHandle:completionHandle];
}


@end
